# -*-coding:utf-8-*-
"""
@project: python-project
@Time: 2024-07-13 9:39
@Author: Loneliness_Burial
@File: 查询数据.py
@Motto: 深情不改必坠死海
@software: pycharm
@version: python 3.7
"""

import sqlite3

conn = sqlite3.connect('D:\Desktop\LCConfigDataBase')
cursor = conn.cursor()
cursor.execute('SELECT * FROM login')
cursor.execute('SELECT * FROM login ORDER BY id DESC LIMIT 2')  # 查询最后10条数据
cursor.execute('SELECT * FROM login ORDER BY id ASC  LIMIT 2')  # 查询前10条数据
# rows = cursor.fetchall()
# results = []
# for row in rows:
#     print(f"{row[0]}\t{row[1]}\t{row[2]}\t{row[3]}\t{row[4]}\t{row[5]}\t{row[6]}\t{row[7]}\t{row[8]}")
colums = [description[0] for description in cursor.description]
rows = cursor.fetchall()
print(" ".join(colums))
print("-" * (len(colums) * 10))
for row in rows:
    formatted_row = []
    for i, value in enumerate(row):
        formatted_row.append(str(value) if value is not None else '')
    print(" ".join(formatted_row))
cursor.close()
conn.commit()
conn.close()
